from selenium import webdriver
from pprint import pprint

# 打开浏览器 请求测试网址
driver = webdriver.Chrome()
driver.get('https://www.baidu.com')

# 操作cookie
# driver.get_cookies获得所有cookie信息
print(driver.get_cookies())
#driver.get_cookies(name)返回特定name的cookie信息
print(driver.get_cookie('BA_HECTOR'))

# driver.add_cookie(cookie_dict)添加cookie,必须有name 和value 值
dict1 = {'name': 'haha', 'value': '11111'}
driver.add_cookie(dict1)
print(driver.get_cookies())

# driver.delete_cookie(name)删除特定(部分)的cookie信息
driver.delete_cookie('haha')
pprint(driver.get_cookies())
#
# driver.delete_all_cookies()删除所有cookie 信息
driver.delete_all_cookies()
pprint(driver.get_cookies())

# 退出浏览器
driver.quit()


